#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Software : PyCharm
# @Time    : 2024-12-18 11:07
# @Author  : gzh
# @File : Messagebox.py
"""
本文档中的parent均为TkModek的实例中的  实例属性parent即__init__.py 中的 _Tks
"""
from tkinter import Toplevel, Frame, Label, Button, Entry, StringVar, DoubleVar
from tkinter.ttk import Progressbar


class ShowInfo(Toplevel):
    def __init__(self, parent, title='', message=''):
        super().__init__(parent)
        self.wm_overrideredirect(True)
        self.wm_attributes("-topmost", True)
        self.free_w = int(500 * parent.winfo_ki)
        self.free_h = int(350 * parent.winfo_ki)
        self.x_position = int((parent.now_w - self.free_w) / 2)
        self.y_position = int((parent.now_h - self.free_h) / 2)
        self.geometry(
            f'{self.free_w}x{self.free_h}+{self.x_position + parent.winfo_rootx()}+{self.y_position + parent.winfo_rooty()}')
        self._drag_data = {"x": 0, "y": 0, "is_dragging": False}
        top_label = Label(self, text=title, font=parent.f18, bd=0, bg='#3E77F8', fg='black')
        top_label.place(relx=0, rely=0, relwidth=1, relheight=0.15)
        top_label.bind("<Button-1>", lambda event: self.on_titlebar_click(event))
        top_label.bind("<B1-Motion>", self.on_drag_motion)
        Label(self, text=message, font=parent.f18, bd=0, wraplength=480,
              fg='black').place(relx=0, rely=0.15, relwidth=1, relheight=0.65)
        frm = Frame(self, bd=0, bg='#FFFFFF')
        frm.place(relx=0, rely=0.8, relwidth=1, relheight=0.2)
        bt1 = Button(frm, text='确认', font=parent.f18, wraplength=340, command=self.destroy, bd=2, fg='#000000')
        bt1.place(relx=0.35, rely=0.15, relwidth=0.3, relheight=0.7)
        bt1.bind('<Return>', lambda event: self.destroy())

        self.grab_set()

    def on_titlebar_click(self, event):
        self._drag_data["x"] = event.x_root - self.winfo_rootx()
        self._drag_data["y"] = event.y_root - self.winfo_rooty()

    def on_drag_motion(self, event):
        x_new = event.x_root - self._drag_data["x"]
        y_new = event.y_root - self._drag_data["y"]
        self.geometry(f'{self.winfo_width()}x{self.winfo_height()}+{x_new}+{y_new}')


class AskYesNo(Toplevel):
    def __init__(self, parent, fanc, title='', message='', *args):
        super().__init__(parent)
        self.wm_overrideredirect(True)
        self.wm_attributes("-topmost", True)
        self.free_w = int(500 * parent.winfo_ki)
        self.free_h = int(350 * parent.winfo_ki)
        self.x_position = int((parent.now_w - self.free_w) / 2)
        self.y_position = int((parent.now_h - self.free_h) / 2)
        self.geometry(
            f'{self.free_w}x{self.free_h}+{self.x_position + parent.winfo_rootx()}+{self.y_position + parent.winfo_rooty()}')
        self._drag_data = {"x": 0, "y": 0, "is_dragging": False}

        top_label = Label(self, text=title, font=parent.f18, bd=0, bg='#3E77F8', fg='black')
        top_label.place(relx=0, rely=0, relwidth=1, relheight=0.15)
        top_label.bind("<Button-1>", lambda event: self.on_titlebar_click(event))
        top_label.bind("<B1-Motion>", self.on_drag_motion)
        Label(self, text=message, font=parent.f18, bd=0, wraplength=460,
              fg='black').place(relx=0, rely=0.15, relwidth=1, relheight=0.65)
        frm = Frame(self, bd=0, bg='#FFFFFF')
        frm.place(relx=0, rely=0.8, relwidth=1, relheight=0.2)
        bt1 = Button(frm, text='是', font=parent.f18, wraplength=480, command=self.btn_ok, bd=2, fg='#000000')
        bt1.place(relx=0.1, rely=0.15, relwidth=0.3, relheight=0.7)
        bt2 = Button(frm, text='否', font=parent.f18, wraplength=340, command=self.btn_nok, bd=2, fg='#000000')
        bt2.place(relx=0.6, rely=0.15, relwidth=0.3, relheight=0.7)
        bt1.bind('<Return>', lambda event,: self.btn_ok())
        bt2.bind('<Return>', lambda event,: self.btn_nok())

        self.fanc = fanc
        self.args = args
        self.grab_set()

    def on_titlebar_click(self, event):
        self._drag_data["x"] = event.x_root - self.winfo_rootx()
        self._drag_data["y"] = event.y_root - self.winfo_rooty()

    def on_drag_motion(self, event):
        x_new = event.x_root - self._drag_data["x"]
        y_new = event.y_root - self._drag_data["y"]
        self.geometry(f'{self.winfo_width()}x{self.winfo_height()}+{x_new}+{y_new}')

    def btn_ok(self):
        self.fanc(*self.args)
        self.destroy()

    def btn_nok(self):
        self.destroy()


class AskYesNoNew(Toplevel):
    def __init__(self, parent, title='', message=''):
        super().__init__(parent)
        self.wm_overrideredirect(True)
        self.wm_attributes("-topmost", True)
        self.free_w = int(500 * parent.winfo_ki)
        self.free_h = int(350 * parent.winfo_ki)
        self.x_position = int((parent.now_w - self.free_w) / 2)
        self.y_position = int((parent.now_h - self.free_h) / 2)
        self.geometry(
            f'{self.free_w}x{self.free_h}+{self.x_position + parent.winfo_rootx()}+{self.y_position + parent.winfo_rooty()}')
        self._drag_data = {"x": 0, "y": 0, "is_dragging": False}

        top_label = Label(self, text=title, font=parent.f18, bd=0, bg='#3E77F8', fg='black')
        top_label.place(relx=0, rely=0, relwidth=1, relheight=0.15)
        top_label.bind("<Button-1>", lambda event: self.on_titlebar_click(event))
        top_label.bind("<B1-Motion>", self.on_drag_motion)
        Label(self, text=message, font=parent.f18, bd=0, wraplength=460,
              fg='black').place(relx=0, rely=0.15, relwidth=1, relheight=0.65)
        frm = Frame(self, bd=0, bg='#FFFFFF')
        frm.place(relx=0, rely=0.8, relwidth=1, relheight=0.2)
        bt1 = Button(frm, text='是', font=parent.f18, wraplength=480, command=self.btn_ok, bd=2, fg='#000000')
        bt1.place(relx=0.1, rely=0.15, relwidth=0.3, relheight=0.7)
        bt2 = Button(frm, text='否', font=parent.f18, wraplength=340, command=self.btn_nok, bd=2, fg='#000000')
        bt2.place(relx=0.6, rely=0.15, relwidth=0.3, relheight=0.7)
        bt1.bind('<Return>', lambda event,: self.btn_ok())
        bt2.bind('<Return>', lambda event,: self.btn_nok())
        self.result = None
        self.grab_set()

    def show(self):
        """显示对话框并返回用户选择"""
        self.deiconify()  # 确保窗口已创建后再调用 deiconify
        self.wait_window()  # 等待窗口关闭
        return self.result

    def on_titlebar_click(self, event):
        self._drag_data["x"] = event.x_root - self.winfo_rootx()
        self._drag_data["y"] = event.y_root - self.winfo_rooty()

    def on_drag_motion(self, event):
        x_new = event.x_root - self._drag_data["x"]
        y_new = event.y_root - self._drag_data["y"]
        self.geometry(f'{self.winfo_width()}x{self.winfo_height()}+{x_new}+{y_new}')

    def btn_ok(self):
        self.result = True
        self.destroy()

    def btn_nok(self):
        self.result = False
        self.destroy()


class DoYesNo(Toplevel):
    def __init__(self, parent, fanc, title='', message='', *args):
        super().__init__(parent)
        self.wm_overrideredirect(True)
        self.wm_attributes("-topmost", True)
        self.free_w = int(500 * parent.winfo_ki)
        self.free_h = int(350 * parent.winfo_ki)
        self.x_position = int((parent.now_w - self.free_w) / 2)
        self.y_position = int((parent.now_h - self.free_h) / 2)
        self.geometry(
            f'{self.free_w}x{self.free_h}+{self.x_position + parent.winfo_rootx()}+{self.y_position + parent.winfo_rooty()}')
        self._drag_data = {"x": 0, "y": 0, "is_dragging": False}

        top_label = Label(self, text=title, font=parent.f18, bd=0, bg='#3E77F8', fg='black')
        top_label.place(relx=0, rely=0, relwidth=1, relheight=0.15)
        top_label.bind("<Button-1>", lambda event: self.on_titlebar_click(event))
        top_label.bind("<B1-Motion>", self.on_drag_motion)
        Label(self, text=message, font=parent.f18, bd=0, wraplength=460,
              fg='black').place(relx=0, rely=0.15, relwidth=1, relheight=0.65)
        frm = Frame(self, bd=0, bg='#FFFFFF')
        frm.place(relx=0, rely=0.8, relwidth=1, relheight=0.2)
        bt1 = Button(frm, text='是', font=parent.f18, wraplength=480, command=self.btn_ok, bd=2, fg='#000000')
        bt1.place(relx=0.1, rely=0.15, relwidth=0.3, relheight=0.7)
        bt2 = Button(frm, text='否', font=parent.f18, wraplength=340, command=self.btn_nok, bd=2, fg='#000000')
        bt2.place(relx=0.6, rely=0.15, relwidth=0.3, relheight=0.7)
        bt1.bind('<Return>', lambda event,: self.btn_ok())
        bt2.bind('<Return>', lambda event,: self.btn_nok())

        self.fanc = fanc
        self.args = args
        self.grab_set()

    def on_titlebar_click(self, event):
        self._drag_data["x"] = event.x_root - self.winfo_rootx()
        self._drag_data["y"] = event.y_root - self.winfo_rooty()

    def on_drag_motion(self, event):
        x_new = event.x_root - self._drag_data["x"]
        y_new = event.y_root - self._drag_data["y"]
        self.geometry(f'{self.winfo_width()}x{self.winfo_height()}+{x_new}+{y_new}')

    def btn_ok(self):
        self.fanc(True, *self.args)
        self.destroy()

    def btn_nok(self):
        self.fanc(False, *self.args)
        self.destroy()


class InputVar(Toplevel):
    def __init__(self, parent, var_input):
        super().__init__(parent)
        self.wm_overrideredirect(True)
        self.wm_attributes("-topmost", True)
        self.free_w = int(500 * parent.winfo_ki)
        self.free_h = int(350 * parent.winfo_ki)
        self.x_position = int((parent.now_w - self.free_w) / 2)
        self.y_position = int((parent.now_h - self.free_h) / 2)
        self.geometry(
            f'{self.free_w}x{self.free_h}+{self.x_position + parent.winfo_rootx()}+{self.y_position + parent.winfo_rooty()}')
        self.config(bg='#f07f7f')
        self.parent = parent
        self.var_input = var_input
        self.old_value = var_input.get()
        Label(self, text='设计锁定轨温:', font=parent.f18, justify='center', bd=0, relief='flat',
              bg='#f07f7f').place(relx=0.15, rely=0.3, relwidth=0.4, relheight=0.1)
        Entry(self, textvariable=self.var_input, font=parent.f18, justify='center',
              bg='#ffffff').place(relx=0.56, rely=0.3, relwidth=0.15, relheight=0.1)
        Label(self, text='℃', font=parent.f18, justify='center', bd=0, relief='flat',
              bg='#f07f7f').place(relx=0.72, rely=0.3, relwidth=0.05, relheight=0.1)

        bt1 = Button(self, text='确定', font=parent.f18, wraplength=480,
                     command=self.btn_ok, bd=2, fg='#000000', bg='green')
        bt1.place(relx=0.1, rely=0.85, relwidth=0.2, relheight=0.1)
        bt2 = Button(self, text='取消', font=parent.f18, wraplength=340,
                     command=self.btn_nok, bd=2, fg='#000000', bg='green')
        bt2.place(relx=0.7, rely=0.85, relwidth=0.2, relheight=0.1)
        bt1.bind('<Return>', lambda event,: self.btn_ok())
        bt2.bind('<Return>', lambda event,: self.btn_nok())
        self.grab_set()

    def btn_ok(self):
        self.destroy()

    def btn_nok(self):
        self.var_input.set(self.old_value)
        self.destroy()


class UserPass(Toplevel):
    def __init__(self, parent, u_name, fanc):
        super().__init__(parent)
        self.wm_overrideredirect(True)
        self.wm_attributes("-topmost", True)
        self.free_w = int(500 * parent.winfo_ki)
        self.free_h = int(350 * parent.winfo_ki)
        self.x_position = int((parent.now_w - self.free_w) / 2)
        self.y_position = int((parent.now_h - self.free_h) / 2)
        self.geometry(
            f'{self.free_w}x{self.free_h}+{self.x_position + parent.winfo_rootx()}+{self.y_position + parent.winfo_rooty()}')
        self.config(bg='#f07f7f')
        self.parent = parent
        self.fanc = fanc
        self.en2 = StringVar(master=self, value='')
        Label(self, text='用户名:', font=parent.f18, justify='center', bd=0, relief='flat',
              bg='#f07f7f').place(relx=0.15, rely=0.3, relwidth=0.4, relheight=0.1)
        Label(self, text=u_name, font=parent.f18, justify='center',
              bg='#ffffff').place(relx=0.56, rely=0.3, relwidth=0.3, relheight=0.1)
        Label(self, text='密码:', font=parent.f18, justify='center', bd=0, relief='flat',
              bg='#f07f7f').place(relx=0.15, rely=0.5, relwidth=0.4, relheight=0.1)
        Entry(self, textvariable=self.en2, font=parent.f18, justify='center',
              bg='#ffffff').place(relx=0.56, rely=0.5, relwidth=0.3, relheight=0.1)

        bt1 = Button(self, text='确定', font=parent.f18, wraplength=480,
                     command=self.btn_ok, bd=2, fg='#000000', bg='green')
        bt1.place(relx=0.1, rely=0.85, relwidth=0.2, relheight=0.1)
        bt2 = Button(self, text='取消', font=parent.f18, wraplength=340,
                     command=self.btn_nok, bd=2, fg='#000000', bg='green')
        bt2.place(relx=0.7, rely=0.85, relwidth=0.2, relheight=0.1)
        bt1.bind('<Return>', lambda event,: self.btn_ok())
        bt2.bind('<Return>', lambda event,: self.btn_nok())
        self.grab_set()

    def btn_ok(self):
        self.fanc(self.en2)
        self.destroy()

    def btn_nok(self):
        self.destroy()


class ProgressBox(Toplevel):
    def __init__(self, parent, fanc1, fanc, message='', *args):
        super().__init__(parent)
        try:
            float(args[16].get())
        except:
            ShowInfo(parent, '', "施工锁定轨温设置有误")
            self.destroy()
            return
        self.wm_overrideredirect(True)
        self.wm_attributes("-topmost", True)
        self.free_w = int(500 * parent.winfo_ki)
        self.free_h = int(350 * parent.winfo_ki)
        self.x_position = int((parent.now_w - self.free_w) / 2)
        self.y_position = int((parent.now_h - self.free_h) / 2)
        self.geometry(
            f'{self.free_w}x{self.free_h}+{self.x_position + parent.winfo_rootx()}+{self.y_position + parent.winfo_rooty()}')
        self.parent = parent
        self.config(bg='#f07f7f')
        progress_var = DoubleVar(master=self, value=0)  # 进度变量，用于存储进度值
        Label(self, text=message, anchor='center', justify='center', bg='#f07f7f', bd=0, relief='flat',
              font=parent.f13).place(relx=0.1, rely=0.4, relwidth=0.8, relheight=0.05)
        self.progressbar = Progressbar(self, orient="horizontal", mode="determinate", variable=progress_var)
        self.progressbar.place(relx=0.1, rely=0.47, relwidth=0.8, relheight=0.05)
        self.perform_task(progress_var)
        self.grab_set()
        self.fanc = fanc
        self.fanc1 = fanc1
        self.args = args

    def perform_task(self, v):
        v.set(v.get() + 1)  # 更新进度
        if v.get() > 100:
            self.fanc1(*self.args)
            self.progressbar.destroy()
            self.destroy()
            AskYesNo(self.parent, self.fanc, '', '是否保存', *self.args)
        else:
            self.after(10, self.perform_task, v)


class UintSetPass(Toplevel):
    def __init__(self, parent, fanc):
        super().__init__(parent)
        self.wm_overrideredirect(True)
        self.wm_attributes("-topmost", True)
        self.free_w = int(500 * parent.winfo_ki)
        self.free_h = int(350 * parent.winfo_ki)
        self.x_position = int((parent.now_w - self.free_w) / 2)
        self.y_position = int((parent.now_h - self.free_h) / 2)
        self.geometry(
            f'{self.free_w}x{self.free_h}+{self.x_position + parent.winfo_rootx()}+{self.y_position + parent.winfo_rooty()}')
        self.config(bg='#f07f7f')
        self.parent = parent
        self.en2 = StringVar(master=self, value='')
        Label(self, text='维护密码:', font=parent.f18, justify='center', bd=0, relief='flat',
              bg='#f07f7f').place(relx=0.15, rely=0.5, relwidth=0.4, relheight=0.1)
        Entry(self, textvariable=self.en2, font=parent.f18, justify='center',
              bg='#ffffff').place(relx=0.56, rely=0.5, relwidth=0.3, relheight=0.1)

        bt1 = Button(self, text='确定', font=parent.f18, wraplength=480,
                     command=self.btn_ok, bd=2, fg='#000000', bg='green')
        bt1.place(relx=0.1, rely=0.85, relwidth=0.2, relheight=0.1)
        bt2 = Button(self, text='取消', font=parent.f18, wraplength=340,
                     command=self.btn_nok, bd=2, fg='#000000', bg='green')
        bt2.place(relx=0.7, rely=0.85, relwidth=0.2, relheight=0.1)
        bt1.bind('<Return>', lambda event,: self.btn_ok())
        bt2.bind('<Return>', lambda event,: self.btn_nok())

        self.fanc = fanc
        self.grab_set()

    def btn_ok(self):
        if self.en2.get() == '20250120':
            self.fanc()
            self.destroy()
        else:
            ShowInfo(self.parent, '', '密码错误！！！')

    def btn_nok(self):
        self.destroy()


class KeyBordTop(Toplevel):
    def __init__(self, parent, entry):
        super().__init__(parent)
        self.parent = parent
        self.data_old = entry.get()
        self.entry = entry
        self.entry.set('')
        self.wm_overrideredirect(True)
        self.wm_attributes("-topmost", True)
        self.free_w = int(600 * parent.winfo_ki)
        self.free_h = int(400 * parent.winfo_ki)
        self.x_position = int((parent.now_w - self.free_w) / 2)
        self.y_position = int((parent.now_h - self.free_h) / 2)
        self.geometry(
            f'{self.free_w}x{self.free_h}+{self.x_position + parent.winfo_rootx()}+{self.y_position + parent.winfo_rooty()}')
        self._drag_data = {"x": 0, "y": 0, "is_dragging": False}

        top_label = Label(self, text='keybord', font=parent.f18, bd=0, bg='#3E77F8', fg='black')
        top_label.place(relx=0, rely=0, relwidth=1, relheight=0.1)
        top_label.bind("<Button-1>", lambda event: self.on_titlebar_click(event))
        top_label.bind("<B1-Motion>", self.on_drag_motion)

        self.st_label_name = StringVar(self, value='0')
        Entry(self, font=('Arial', 40, 'bold'), textvariable=self.st_label_name,
              state='readonly').place(relx=0.1, rely=0.1, relheight=0.2, relwidth=0.7)
        frm1 = Frame(self, bd=0, bg='#FFFFFF')
        frm1.place(relx=0, rely=0.3, relwidth=1, relheight=0.7)
        frm2 = Frame(self, bd=0, bg='#FFFFFF')
        bt1 = Button(self, text='ABC', font=parent.f18, command=lambda: self.change_num_ABC(bt1, frm1, frm2))
        bt1.place(relx=0.81, rely=0.1, relwidth=0.15, relheight=0.2)
        self.num_key(frm1)
        self.ABC_key(frm2)

        self.grab_set()

    @staticmethod
    def change_num_ABC(bt1, frm1, frm2):
        if bt1.cget('text') == 'ABC':
            bt1.config(text='123')
            frm1.place_forget()
            frm2.place(relx=0, rely=0.3, relwidth=1, relheight=0.7)
        else:
            bt1.config(text='ABC')
            frm2.place_forget()
            frm1.place(relx=0, rely=0.3, relwidth=1, relheight=0.7)

    def on_titlebar_click(self, event):
        self._drag_data["x"] = event.x_root - self.winfo_rootx()
        self._drag_data["y"] = event.y_root - self.winfo_rooty()

    def on_drag_motion(self, event):
        x_new = event.x_root - self._drag_data["x"]
        y_new = event.y_root - self._drag_data["y"]
        self.geometry(f'{self.winfo_width()}x{self.winfo_height()}+{x_new}+{y_new}')

    def num_key(self, frm):
        h = 0.16
        w = 0.17
        Button(frm, text='7', font=self.parent.f20, command=lambda: self.label_edit(7)) \
            .place(relx=0.1, rely=0.1, relwidth=w, relheight=h)
        Button(frm, text='8', font=self.parent.f20, command=lambda: self.label_edit(8)) \
            .place(relx=0.3, rely=0.1, relwidth=w, relheight=h)
        Button(frm, text='9', font=self.parent.f20, command=lambda: self.label_edit(9)) \
            .place(relx=0.5, rely=0.1, relwidth=w, relheight=h)
        Button(frm, text='4', font=self.parent.f20, command=lambda: self.label_edit(4)) \
            .place(relx=0.1, rely=0.3, relwidth=w, relheight=h)
        Button(frm, text='5', font=self.parent.f20, command=lambda: self.label_edit(5)) \
            .place(relx=0.3, rely=0.3, relwidth=w, relheight=h)
        Button(frm, text='6', font=self.parent.f20, command=lambda: self.label_edit(6)) \
            .place(relx=0.5, rely=0.3, relwidth=w, relheight=h)
        Button(frm, text='1', font=self.parent.f20, command=lambda: self.label_edit(1)) \
            .place(relx=0.1, rely=0.5, relwidth=w, relheight=h)
        Button(frm, text='2', font=self.parent.f20, command=lambda: self.label_edit(2)) \
            .place(relx=0.3, rely=0.5, relwidth=w, relheight=h)
        Button(frm, text='3', font=self.parent.f20, command=lambda: self.label_edit(3)) \
            .place(relx=0.5, rely=0.5, relwidth=w, relheight=h)
        Button(frm, text='0', font=self.parent.f20, command=lambda: self.label_edit(0)) \
            .place(relx=0.7, rely=0.3, relwidth=w, relheight=h)
        Button(frm, text='确认', bg='blue', font=self.parent.f18, command=self.label_edit_OK) \
            .place(relx=0.7, rely=0.5, relwidth=w, relheight=h)
        Button(frm, bg='blue', text='删除', font=self.parent.f18, command=lambda: self.label_edit(14)) \
            .place(relx=0.7, rely=0.1, relwidth=w, relheight=h)

    def ABC_key(self, frm):
        h = 0.15
        w = 0.1
        Button(frm, text='A', font=self.parent.f20, command=lambda: self.label_edit('A')) \
            .place(relx=0.1, rely=0.1, relwidth=w, relheight=h)
        Button(frm, text='B', font=self.parent.f20, command=lambda: self.label_edit('B')) \
            .place(relx=0.2, rely=0.1, relwidth=w, relheight=h)
        Button(frm, text='C', font=self.parent.f20, command=lambda: self.label_edit('C')) \
            .place(relx=0.3, rely=0.1, relwidth=w, relheight=h)
        Button(frm, text='D', font=self.parent.f20, command=lambda: self.label_edit('D')) \
            .place(relx=0.4, rely=0.1, relwidth=w, relheight=h)
        Button(frm, text='E', font=self.parent.f20, command=lambda: self.label_edit('E')) \
            .place(relx=0.5, rely=0.1, relwidth=w, relheight=h)
        Button(frm, text='F', font=self.parent.f20, command=lambda: self.label_edit('F')) \
            .place(relx=0.6, rely=0.1, relwidth=w, relheight=h)
        Button(frm, text='G', font=self.parent.f20, command=lambda: self.label_edit('G')) \
            .place(relx=0.7, rely=0.1, relwidth=w, relheight=h)
        Button(frm, text='H', font=self.parent.f20, command=lambda: self.label_edit('H')) \
            .place(relx=0.8, rely=0.1, relwidth=w, relheight=h)
        Button(frm, text='I', font=self.parent.f20, command=lambda: self.label_edit('I')) \
            .place(relx=0.1, rely=0.3, relwidth=w, relheight=h)
        Button(frm, text='J', font=self.parent.f20, command=lambda: self.label_edit('J')) \
            .place(relx=0.2, rely=0.3, relwidth=w, relheight=h)
        Button(frm, text='K', font=self.parent.f20, command=lambda: self.label_edit('K')) \
            .place(relx=0.3, rely=0.3, relwidth=w, relheight=h)
        Button(frm, text='L', font=self.parent.f20, command=lambda: self.label_edit('L')) \
            .place(relx=0.4, rely=0.3, relwidth=w, relheight=h)
        Button(frm, text='M', font=self.parent.f20, command=lambda: self.label_edit('M')) \
            .place(relx=0.5, rely=0.3, relwidth=w, relheight=h)
        Button(frm, text='N', font=self.parent.f20, command=lambda: self.label_edit('N')) \
            .place(relx=0.6, rely=0.3, relwidth=w, relheight=h)
        Button(frm, text='O', font=self.parent.f20, command=lambda: self.label_edit('O')) \
            .place(relx=0.7, rely=0.3, relwidth=w, relheight=h)
        Button(frm, text='P', font=self.parent.f20, command=lambda: self.label_edit('P')) \
            .place(relx=0.8, rely=0.3, relwidth=w, relheight=h)
        Button(frm, text='Q', font=self.parent.f20, command=lambda: self.label_edit('Q')) \
            .place(relx=0.1, rely=0.5, relwidth=w, relheight=h)
        Button(frm, text='R', font=self.parent.f20, command=lambda: self.label_edit('R')) \
            .place(relx=0.2, rely=0.5, relwidth=w, relheight=h)
        Button(frm, text='S', font=self.parent.f20, command=lambda: self.label_edit('S')) \
            .place(relx=0.3, rely=0.5, relwidth=w, relheight=h)
        Button(frm, text='T', font=self.parent.f20, command=lambda: self.label_edit('T')) \
            .place(relx=0.4, rely=0.5, relwidth=w, relheight=h)
        Button(frm, text='U', font=self.parent.f20, command=lambda: self.label_edit('U')) \
            .place(relx=0.5, rely=0.5, relwidth=w, relheight=h)
        Button(frm, text='V', font=self.parent.f20, command=lambda: self.label_edit('V')) \
            .place(relx=0.6, rely=0.5, relwidth=w, relheight=h)
        Button(frm, text='W', font=self.parent.f20, command=lambda: self.label_edit('W')) \
            .place(relx=0.7, rely=0.5, relwidth=w, relheight=h)
        Button(frm, text='X', font=self.parent.f20, command=lambda: self.label_edit('X')) \
            .place(relx=0.8, rely=0.5, relwidth=w, relheight=h)
        Button(frm, text='Y', font=self.parent.f20, command=lambda: self.label_edit('Y')) \
            .place(relx=0.1, rely=0.7, relwidth=w, relheight=h)
        Button(frm, text='Z', font=self.parent.f20, command=lambda: self.label_edit('Z')) \
            .place(relx=0.2, rely=0.7, relwidth=w, relheight=h)
        Button(frm, text='.', font=self.parent.f20, command=lambda: self.label_edit(10)) \
            .place(relx=0.3, rely=0.7, relwidth=w, relheight=h)
        Button(frm, text=':', font=self.parent.f20, command=lambda: self.label_edit(13)) \
            .place(relx=0.4, rely=0.7, relwidth=w, relheight=h)
        Button(frm, text='空格', font=self.parent.f20, command=lambda: self.label_edit(11)) \
            .place(relx=0.5, rely=0.7, relwidth=w, relheight=h)
        Button(frm, text='-', font=self.parent.f20, command=lambda: self.label_edit(12)) \
            .place(relx=0.6, rely=0.7, relwidth=w, relheight=h)
        Button(frm, text='确认', bg='blue', font=self.parent.f18, command=self.label_edit_OK) \
            .place(relx=0.8, rely=0.7, relwidth=w, relheight=h)
        Button(frm, bg='blue', text='删除', font=self.parent.f18, command=lambda: self.label_edit(14)) \
            .place(relx=0.7, rely=0.7, relwidth=w, relheight=h)

    # 字模加标签
    def Label_edit_Ctr(self, key_n):
        b = self.st_label_name.get()
        if key_n == 10:  # 点
            b += '.'
        elif key_n == 11:  # 空格
            b += ' '
        elif key_n == 12:  # 横杠
            b += '-'
        elif key_n == 13:  # 冒号
            b += ':'
        elif key_n == 14:  # 退格
            b = b[0:-1]
        elif key_n == 15:  # 清空
            b = ''
        else:
            b += str(key_n)
        for i in range(len(b)):
            if len(b) == 1:
                break
            else:
                if b[0] == '0':
                    b = b[1:]
                else:
                    break
        self.st_label_name.set(b)

    def label_edit(self, data):
        self.Label_edit_Ctr(data)

    def label_edit_ABC(self, data):
        self.Label_edit_Ctr(data)

    def label_edit_OK(self):
        b = self.st_label_name.get()
        self.entry.set(b)
        self.destroy()

    def label_edit_Esc(self):
        self.entry.set(self.data_old)
        self.destroy()
